import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import request from 'utils/request';
import { CPAAS_MSG } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 查询消息查询列表数据
 * @async
 * @function queryMessageList
 * @param {object} params - 查询条件
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */

export function queryMessageList(_x) {
  return _queryMessageList.apply(this, arguments);
}
/**
 * 查看内容
 * @async
 * @function queryContent
 * @param {object} params - 查询条件
 * @param {!number} params.messageId - 消息id
 * @returns {object} fetch Promise
 */

function _queryMessageList() {
  _queryMessageList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(parmas) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages") : "".concat(CPAAS_MSG, "/v1/messages"), {
              method: 'GET',
              query: _objectSpread({}, parmas)
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryMessageList.apply(this, arguments);
}

export function queryContent(_x2) {
  return _queryContent.apply(this, arguments);
}
/**
 * 查询收件人
 * @async
 * @function queryRecipient
 * @param {object} params,messageId - 查询条件
 * @param {!number} messageId - 消息id
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */

function _queryContent() {
  _queryContent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(parmas) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/").concat(parmas, "/contents") : "".concat(CPAAS_MSG, "/v1/messages/").concat(parmas, "/contents")));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryContent.apply(this, arguments);
}

export function queryRecipient(_x3, _x4) {
  return _queryRecipient.apply(this, arguments);
}
/**
 * 查看错误
 * @async
 * @function queryError
 * @param {object} transactionId - 查询条件
 * @param {!number} transactionId - transactionId
 * @returns {object} fetch Promise
 */

function _queryRecipient() {
  _queryRecipient = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(messageId, parmas) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/").concat(messageId, "/receivers") : "".concat(CPAAS_MSG, "/v1/messages/").concat(messageId, "/receivers"), {
              method: 'GET',
              query: _objectSpread({}, parmas)
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryRecipient.apply(this, arguments);
}

export function queryError(_x5) {
  return _queryError.apply(this, arguments);
}
/**
 * 重试
 * @async
 * @function resendMessage
 * @param {object} transactionId - 查询条件
 * @param {!number} transactionId - transactionId
 * @returns {object} fetch Promise
 */

function _queryError() {
  _queryError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(transactionId) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/transactions") : "".concat(CPAAS_MSG, "/v1/messages/transactions"), {
              method: 'GET',
              query: {
                transactionId: transactionId
              }
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _queryError.apply(this, arguments);
}

export function resendMessage(_x6) {
  return _resendMessage.apply(this, arguments);
}
/**
 * 删除
 * @async
 * @function deleteMessage
 * @param {array} params - 查询条件
 * @returns {object} fetch Promise
 */

function _resendMessage() {
  _resendMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(transactionId) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/resend") : "".concat(CPAAS_MSG, "/v1/messages/resend"), {
              method: 'POST',
              query: {
                transactionId: transactionId
              }
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _resendMessage.apply(this, arguments);
}

export function deleteMessage(_x7) {
  return _deleteMessage.apply(this, arguments);
}

function _deleteMessage() {
  _deleteMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages") : "".concat(CPAAS_MSG, "/v1/messages"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _deleteMessage.apply(this, arguments);
}